
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class StudentSort {
    public static void main(String[] args) {
        try {
            List<Student> list = new ArrayList<Student>();
            list.add(new Student("002", "张1", 35));
            list.add(new Student("001", "张2", 32));
            list.add(new Student("003", "张3", 30));
            Collections.sort(list);
            System.out.println(list);
            Collections.sort(list, new Comparator<Student>() {
                public int compare(Student s1, Student s2) {
                    return s1.getStudentName().compareTo(s2.getStudentName());
                }
            });
            System.out.println(list);
            Collections.sort(list, new Comparator<Student>() {
                public int compare(Student s1, Student s2) {
                    return s1.getAge() - s2.getAge();
                }
            });
            System.out.println(list);
        } catch (Exception e) {
            System.out.println("出现错误：" + e.getMessage());
        }
    }
}

